package net.tycmc.cty.ctyms.web.maintAlertManual;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.cty.ctyms.timejob.common.MyBaseDAO;

public class MaintAlertManualDao {
	private IBaseDAO baseDAO;
	private MyBaseDAO mbd;

	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	public MyBaseDAO getMbd() {
		return mbd; 
	}

	public void setMbd(MyBaseDAO mbd) {
		this.mbd = mbd;
	}

	//保养计划提醒信息 列表数量
	public int[] getInfoListCount() {
		String today = DateUtil.addDay(0)+" 00:00:00.000";
		String yesterday = DateUtil.addDay(-1)+" 00:00:00.000";
		String beforeYesterday = DateUtil.addDay(-2)+" 00:00:00.000";
		String sql = "select count(*) as count from Mtn_Alarm_InfoList where MtnAL_AlarmDate=?";
		int count1 = baseDAO.getCount(sql, new Object[]{today});
		int count2 = baseDAO.getCount(sql, new Object[]{yesterday});
		int count3 = baseDAO.getCount(sql, new Object[]{beforeYesterday});
		int[] result = {count1,count2,count3};
		return result;
	}
	
	//保养计划提醒信息 表数量
	public int[] getCount(){
		String today = DateUtil.addDay(0)+" 00:00:00.000";
		String yesterday = DateUtil.addDay(-1)+" 00:00:00.000";
		String beforeYesterday = DateUtil.addDay(-2)+" 00:00:00.000";
		String sql = "select count(*) as count from Mtn_Alarm_InfoNew where MtnAN_AlarmDate=?";
		int count1 = baseDAO.getCount(sql, new Object[]{today});
		int count2 = baseDAO.getCount(sql, new Object[]{yesterday});
		int count3 = baseDAO.getCount(sql, new Object[]{beforeYesterday});
		int[] result = {count1,count2,count3};
		return result;
	}
	
	//删除数据，重新统计
	public boolean deleteList(){
		String today = DateUtil.addDay(0);
		String tomorrow = DateUtil.addDay(1);
		String todayTime = DateUtil.addDay(0)+" 00:00:00.000";
		String sql1 = "delete from Mtn_Alarm_InfoList where MtnAL_AlarmDate=?";
		String sql2 = "delete from Mtn_Alarm_InfoNew where MtnAN_AlarmDate=?";
		String sql3 = "delete from Note_MaintAlerts where CONVERT(varchar(10),NMA_SendTime,120)=? or CONVERT(varchar(10),NMA_SendTime,120)=?"; 
		int flag1 = baseDAO.execUpdate(sql1, new Object[]{todayTime});
		int flag2 = baseDAO.execUpdate(sql2, new Object[]{todayTime});
		int flag3 = baseDAO.execUpdate(sql3, new Object[]{today,tomorrow});
		if(flag1>=0 && flag2>=0 && flag3>=0){
			return true;
		}else{
			return false;
		}
	}
}
